using System;
using System.ComponentModel;
using System.Security.Permissions;
using System.Web;
using PickGold.Charting.Utilities;

namespace PickGold.Charting
{
	[EditorBrowsable(EditorBrowsableState.Never)]
	[TypeConverter(typeof(CustomPropertiesTypeConverter))]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class CustomProperties
	{
		internal DataPointCustomProperties _DataPointCustomProperties;

		internal CustomProperties(DataPointCustomProperties properties)
		{
			this._DataPointCustomProperties = properties;
		}

		internal virtual string GetUserDefinedCustomProperties()
		{
			return this.GetUserDefinedCustomProperties(true);
		}

		internal virtual string GetUserDefinedCustomProperties(bool userDefined)
		{
			var customProperties = this.DataPointCustomProperties.CustomProperties;
			var str2 = string.Empty;
			var service = this.DataPointCustomProperties.Common.container.GetService(typeof(CustomPropertyRegistry)) as CustomPropertyRegistry;
			customProperties = customProperties.Replace(@"\,", @"\x45").Replace(@"\=", @"\x46");
			if (customProperties.Length > 0)
			{
				foreach (var str3 in customProperties.Split(new char[] { ',' }))
				{
					string[] strArray2 = str3.Split(new char[] { '=' });
					if (strArray2.Length != 2)
						throw new FormatException(SR.ExceptionAttributeInvalidFormat);

					strArray2[0] = strArray2[0].Trim();
					strArray2[1] = strArray2[1].Trim();
					if (strArray2[0].Length == 0)
						throw new FormatException(SR.ExceptionAttributeInvalidFormat);

					var flag = true;
					foreach (CustomPropertyInfo info in service.registeredCustomProperties)
					{
						if (string.Compare(info.Name, strArray2[0], StringComparison.OrdinalIgnoreCase) == 0)
							flag = false;
					}
					if (flag == userDefined)
					{
						if (str2.Length > 0)
							str2 = str2 + ", ";
						string str4 = strArray2[1].Replace(@"\x45", ",").Replace(@"\x46", "=");
						str2 = str2 + strArray2[0] + "=" + str4;
					}
				}
			}
			return str2;
		}

		internal virtual void SetUserDefinedAttributes(string val)
		{
			var userDefinedCustomProperties = this.GetUserDefinedCustomProperties(false);
			if (val.Length > 0)
			{
				if (userDefinedCustomProperties.Length > 0)
				{
					userDefinedCustomProperties = userDefinedCustomProperties + ", ";
				}
				userDefinedCustomProperties = userDefinedCustomProperties + val;
			}
			this.DataPointCustomProperties.CustomProperties = userDefinedCustomProperties;
		}

		internal virtual DataPointCustomProperties DataPointCustomProperties
		{
			get
			{
				return this._DataPointCustomProperties;
			}
			set
			{
				this._DataPointCustomProperties = value;
			}
		}
	}
}

